import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        Token: "",
        username: ""
    },
    mutations: {
        setToken(state, payload) {
            state.Token = payload;

            // 需要缓存在浏览器中
            window.localStorage.setItem("myToken", payload)
        },
        setUsername(state, payload) {
            state.username = payload;
            window.localStorage.setItem("username", payload)

        },
        getClone() {
            window.localStorage.removeItem("myToken");
        }
    },
    getters: {
        getToken(state) {
            if (state.Token) {
                return state.Token
            }
            return localStorage.getItem("myToken")
        },
        getUsername(state) {
            if (state.username) {
                return state.username
            }
            return localStorage.getItem("username")
        },

    },
    modules: {}
})